home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-12-12 | 2.1 KB | 137 lines | [TEXT/R*ch] |
- /***
- *
- * Format FTP Listing.bob
- *
- * Take an FTP directory listing (as produced by Anarchie)
- * and reformat it to a more legible form.
- *
- ***/
-
- main ()
- {
- tabSize = 4; // Width of tab
- width = 10; // Width of file name column (x tabSize)
- while (getfile("TEXT"))
- Convert(""); // The string should be the modification date of the file
- }
-
-
- class List {
- len, items;
- Clear(); GetLen(); GetItems();
- GetItem(n); Append(x);
- }
-
- List::List (maxLen)
- {
- len = 0;
- items = newvector(maxLen);
- return this;
- }
-
- List::Clear ()
- {
- len = 0;
- }
-
- List::GetLen ()
- {
- return len;
- }
-
- List::GetItems ()
- {
- return items;
- }
-
- List::GetItem (n)
- {
- return items[n];
- }
-
- List::Append (x)
- {
- items[len++] = x;
- }
-
-
- Read_tab_delimited_line (list ; c, buf)
- {
- if (typeof(list) == 0) // if (list == nil)
- list = new List(10);
- else
- list.Clear();
- buf = "";
-
- while ((c = getc(stdin)) != -1) {
- if (c == '\t' || c == '\n') {
- list.Append(buf);
- buf = "";
- if (c == '\n')
- return list;
- } else
- buf += c;
- }
- return list;
- }
-
-
- StrEqual (a, b ; i)
- {
- if (sizeof(a) != sizeof(b))
- return 0;
-
- for (i = 0; i < sizeof(a); ++i)
- if (a[i] != b[i])
- return 0;
- return 1;
- }
-
-
- SubStr (s, f, l ; len, r, i)
- {
- len = sizeof(s) - f;
- if (l > len)
- l = len;
- if (l <= 0) return "";
- r = newstring(l);
- for (i = 0; --l >= 0; )
- r[i++] = s[f++];
- return r;
- }
-
-
- Convert (cDate ; list, s, r, i, dirPre, filePre)
- {
- list = Read_tab_delimited_line(nil);
- s = list.GetItems();
- r = s[list.GetLen() - 1]; // Last item in s
-
- for (i = sizeof(r) - 1; i >= 0; --i)
- if (r[i] == '/')
- break;
-
- dirPre = "Δ\t"; // Directory prefix
- filePre = "\t"; // File prefix
-
- d = StrEqual(s[0], "F") ? filePre : dirPre;
-
- print("ftp://", s[5], "/", SubStr(r, 0, i), "\t", cDate, "\n\n");
- print(d, Pad(s[1], width), Pad(s[2], 2), s[3], "\n");
- while (1) {
- Read_tab_delimited_line(list);
- if (list.GetLen() == 0)
- break;
- d = StrEqual(s[0], "F") ? filePre : dirPre;
- print(d, Pad(s[1], width), Pad(s[2], 2), s[3], "\n");
- }
-
- print("\n\n");
- }
-
-
- Pad (s, n)
- {
- return s + SubStr("\t\t\t\t\t\t\t\t\t\t", 0, n - (sizeof(s) / tabSize));
- }
-